import Request from '@/utils/request/request-util';
import axios from 'axios';
import { Modal } from 'ant-design-vue';



export class KnowledgeApi {
  /**
   * 查询模型列表
   * @param {*} params 
   * @returns 
   */
    static list(params) {
        return Request.get('/airag/knowledge/list', params);
    }

    static add(params) {
        return Request.post('/airag/knowledge/add', params);
    }

    static delete(params) {
        return Request.delete('/airag/knowledge/delete', params);
    }

    static edit(params) {
        return Request.post('/airag/knowledge/edit', params);
    }

    static rebuild(params) {
        return axios.put( `/api/airag/knowledge/rebuild?knowIds=${params}`);
    }

    // 知识库文档

    static knowledgeDocList(params) {
      return Request.get('/airag/knowledge/doc/list',params);
    }

    static knowledgeEditDoc(params) {
      return Request.post('/airag/knowledge/doc/edit', params);
    }

    static knowledgeDeleteBatchDoc(params) {
      return Request.post('/airag/knowledge/doc/deleteBatch', params);
    }

    static knowledgeEmbeddingHitTest(params) {
      let url = '/airag/knowledge/embedding/hitTest/' + params.knowId;
      return Request.get( url, params );
    }

    /**
     * 查询知识库
     * @param params
     */
    static queryKnowledgeBathById = (params) => {
      return Request.get(  '/airag/knowledge/query/batch/byId', params );
    };
}


export const deleteModel = (params, handleSuccess) => {
    Modal.confirm({
      title: '确认删除',
      content: '是否删除名称为'+params.name+'的知识库吗？',
      okText: '确认',
      cancelText: '取消',
      onOk: () => {
        return Request.delete({ url: "/airag/knowledge/delete", params }, { joinParamsToUrl: true }).then(() => {
          handleSuccess();
        });
      },
    });
  };


  const request = axios.create({
    baseURL: '',
    timeout: 5000,
    headers: {
      'Content-Type': 'application/json'
    }
  });




  export const put = (url, data, config = {}) => {
    return request({
      method: 'put',
      url,
      data,
      ...config
    });
  };

  export default request;


